package xyz.gpgl.erp.logic.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import common.util.base.CommonUtil;
import common.util.base.Result;
import common.util.mybatis.plus.layui.Page;
import common.util.mybatis.plus.logic.LogicBaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.gpgl.erp.logic.entity.LogicSharesXpathDetail;
import xyz.gpgl.erp.logic.entity.emeus.LogicSharesXpathDetailEmeus;
import xyz.gpgl.erp.logic.service.ILogicSharesXpathDetailService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liubo
 * @since 2020-10-31
 */
@Slf4j
@Controller
@RequestMapping("/logic/logic_shares_xpath_detail")
public class LogicSharesXpathDetailController extends LogicBaseController<ILogicSharesXpathDetailService, LogicSharesXpathDetail>{

    @Autowired
    private ILogicSharesXpathDetailService iLogicSharesXpathDetailService;

    /**
     * 跳转的列表页面
     * @return 跳转页面
     */
    @RequestMapping("/listPage")
    public Object listPage() {
      return "logicSharesXpathDetail_list";
    }

    /**
     * 列表页面表格数据
     * @param entity 实体对象
     * @param page 分页对象
     * @return page 分页对象
     */
    @ResponseBody
    @RequestMapping("/listData")
    public Object listData(LogicSharesXpathDetail entity, Page<LogicSharesXpathDetail> page) {
        QueryWrapper<LogicSharesXpathDetail> query= new QueryWrapper<>();
        if(CommonUtil.isNotEmpty(entity.getMasterId())){
            query.eq(LogicSharesXpathDetailEmeus.masterId,entity.getMasterId());
            query.orderByAsc(LogicSharesXpathDetailEmeus.sharesKey);
            return Result.success(iLogicSharesXpathDetailService.page(page, query));
        }
        return Result.success();
    }

    /**
     * 跳转到修改页面
     * @param id 唯一主键
     * @param model Spring提供的绑定器
     * @return 修改页面
     */
    @RequestMapping("/editPage")
    public Object editPage(String id, Model model) {
        if(CommonUtil.isNotEmpty(id)) {
            LogicSharesXpathDetail entity = this.iLogicSharesXpathDetailService.getById(id);
            if(CommonUtil.isNotEmpty(entity)) {
                model.addAttribute("entity",entity);
            }
        }
        return "logicSharesXpathDetail_edit";
    }

    /**
     * 数据保存
     * @param entity 实体类
     * @return Result 统一结果对象
     */
    @ResponseBody
    @RequestMapping("/save")
    public Object save(@RequestBody LogicSharesXpathDetail entity) {
        log.info("开始保存数据:{}" ,entity);
        this.iLogicSharesXpathDetailService.saveOrUpdate(entity);
        return Result.success();
    }

    /**
     * 数据删除
     * @param entity 实体类
     * @return Result 统一结果对象
     */
    @ResponseBody
    @RequestMapping("/removed")
    public Object removed(LogicSharesXpathDetail entity) {
        this.iLogicSharesXpathDetailService.removeById(entity.getId());
        return Result.success();
    }

}
